#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int M = 1e9 + 7;

int t, n, k;
ll inv(ll a, ll p = M)
{
    return (a == 1) ? 1 : inv(p % a, p) * (p - p / a) % p;
}

// a/b % p
ll frac_inv(ll a, ll b, ll p = M)
{
    return ((a % p) * inv(b, p)) % p;
}

// a^b%p
ll qpow(ll a, ll b, ll p = M)
{
    ll res = 1;
    while (b)
    {
        if (b & 1)
            res = (res * a) % p;

        a = (a * a) % p;
        b >>= 1;
    }
    return res;
}
int main()
{
#ifdef LOCAL
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif
    ios::sync_with_stdio(false), cin.tie(0);

    cin >> t;
    while (t--)
    {
        cin >> n >> k;
        ll res = 0;
        ll temp = qpow(2, n - 1);
        if (n & 1)
        {
            // (2^n-1+1)^k
            res = qpow(temp+1, k);
        }
        else
        {
            for (int i = 1; i <= k; i++)
            {
                res = (qpow(temp-1, i - 1) * qpow(temp*2, k - i) + res) % M;
            }

            res = (res + qpow(temp-1, k)) % M;
        }
        cout << res << endl;
    }
    return 0;
}